package com.torry.replay.infras.repo.impl;

import com.torry.replay.infras.entity.LimitUpDO;
import com.torry.replay.infras.mapper.LimitUpMapper;
import com.torry.replay.infras.repo.LimitUpRepository;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author torry.wang
 * @since 2023-12-06
 */
@Service
public class LimitUpRepositoryImpl extends ServiceImpl<LimitUpMapper, LimitUpDO> implements LimitUpRepository {

    @Resource
    private LimitUpMapper limitUpMapper;

    @Override
    public LocalDate getPreviousDay(LocalDate currentDay) {
        String day = limitUpMapper.selectPreviousDay(currentDay);
        if (StringUtils.isBlank(day)) {
            return null;
        }
        return LocalDate.parse(day, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }

    @Override
    public LocalDate getNextDay(LocalDate currentDay) {
        String day = limitUpMapper.selectNextDay(currentDay);
        if (StringUtils.isBlank(day)) {
            return null;
        }
        return LocalDate.parse(day, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }
}
